toolbar: implement minimum and natural sizes in _get_preferred family
authorJonh Wendell <jonh.wendell@intel.com>
Wed, 31 Jul 2013 14:42:50 +0000 (11:42 -0300)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 9 Nov 2013 18:26:35 +0000 (13:26 -0500)
currently it's using the same sizes for natural and minimum, but it
happens that, when it's allowed to use the arrow, the minimum size
can be smaller than natural.

https://bugzilla.gnome.org/show_bug.cgi?id=693227

gtk/gtktoolbar.c

index 3ec7963d8b4d248cfc30497fcb6d79738fef64e5..239798532da22f328036dab6d3915ac404d50de0 100644 (file)
@@ -918,7 +918,8 @@ get_widget_padding_and_border (GtkWidget *widget,
 
 static void
 gtk_toolbar_size_request (GtkWidget      *widget,
-                         GtkRequisition *requisition)
+                         GtkRequisition *min_requisition,
+                         GtkRequisition *nat_requisition)
 {
   GtkToolbar *toolbar = GTK_TOOLBAR (widget);
   GtkToolbarPrivate *priv = toolbar->priv;
@@ -928,10 +929,10 @@ gtk_toolbar_size_request (GtkWidget      *widget,
   gint max_homogeneous_child_width;
   gint max_homogeneous_child_height;
   gint homogeneous_size;
-  gint long_req;
   gint pack_front_size;
   GtkBorder padding;
   guint border_width;
+  gint extra_width, extra_height;
   GtkRequisition arrow_requisition;
   
   max_homogeneous_child_width = 0;
@@ -990,47 +991,43 @@ gtk_toolbar_size_request (GtkWidget      *widget,
 
       pack_front_size += size;
     }
+
+  arrow_requisition.height = 0;
+  arrow_requisition.width = 0;
   
   if (priv->show_arrow)
-    {
-      gtk_widget_get_preferred_size (priv->arrow_button,
+    gtk_widget_get_preferred_size (priv->arrow_button,
                                      &arrow_requisition, NULL);
-
-      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
-       long_req = arrow_requisition.width;
-      else
-       long_req = arrow_requisition.height;
-      
-      /* There is no point requesting space for the arrow if that would take
-       * up more space than all the items combined
-       */
-      long_req = MIN (long_req, pack_front_size);
-    }
-  else
-    {
-      arrow_requisition.height = 0;
-      arrow_requisition.width = 0;
-      
-      long_req = pack_front_size;
-    }
   
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      requisition->width = long_req;
-      requisition->height = MAX (max_child_height, arrow_requisition.height);
+      nat_requisition->width = pack_front_size;
+      nat_requisition->height = MAX (max_child_height, arrow_requisition.height);
+
+      min_requisition->width = priv->show_arrow ? arrow_requisition.width : nat_requisition->width;
+      min_requisition->height = nat_requisition->height;
     }
   else
     {
-      requisition->height = long_req;
-      requisition->width = MAX (max_child_width, arrow_requisition.width);
+      nat_requisition->height = pack_front_size;
+      nat_requisition->width = MAX (max_child_width, arrow_requisition.width);
+
+      min_requisition->height = priv->show_arrow ? arrow_requisition.height : nat_requisition->height;
+      min_requisition->width = nat_requisition->width;
     }
 
   /* Extra spacing */
   border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
   get_widget_padding_and_border (widget, &padding);
 
-  requisition->width += 2 * border_width + padding.left + padding.right;
-  requisition->height += 2 * border_width + padding.top + padding.bottom;
+  extra_width = 2 * border_width + padding.left + padding.right;
+  extra_height = 2 * border_width + padding.top + padding.bottom;
+
+  nat_requisition->width += extra_width;
+  nat_requisition->height += extra_height;
+
+  min_requisition->width += extra_width;
+  min_requisition->height += extra_height;
   
   priv->button_maxw = max_homogeneous_child_width;
   priv->button_maxh = max_homogeneous_child_height;
@@ -1041,11 +1038,14 @@ gtk_toolbar_get_preferred_width (GtkWidget *widget,
                                  gint      *minimum,
                                  gint      *natural)
 {
-  GtkRequisition requisition;
+  GtkRequisition min_requisition, nat_requisition;
 
-  gtk_toolbar_size_request (widget, &requisition);
+  gtk_toolbar_size_request (widget, &min_requisition, &nat_requisition);
 
-  *minimum = *natural = requisition.width;
+  if (minimum)
+    *minimum = min_requisition.width;
+  if (natural)
+    *natural = nat_requisition.width;
 }
 
 static void
@@ -1053,11 +1053,14 @@ gtk_toolbar_get_preferred_height (GtkWidget *widget,
                                   gint      *minimum,
                                   gint      *natural)
 {
-  GtkRequisition requisition;
+  GtkRequisition min_requisition, nat_requisition;
 
-  gtk_toolbar_size_request (widget, &requisition);
+  gtk_toolbar_size_request (widget, &min_requisition, &nat_requisition);
 
-  *minimum = *natural = requisition.height;
+  if (minimum)
+    *minimum = min_requisition.height;
+  if (natural)
+    *natural = nat_requisition.height;
 }
 
 static gint